﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LBoL.Base;
using LBoL.ConfigData;
using LBoL.Core.Battle.BattleActions;
using LBoL.Core.Battle.Interactions;
using LBoL.Core.Battle;
using LBoL.Core.Cards;
using LBoL.Core;
using LBoLEntitySideloader.Attributes;
using ProbeMod.Cards;
using ProbeMod.Cards.Template;
using LBoL.EntityLib.JadeBoxes;

namespace ProbeMod.Cards
{
    /// <summary>
    /// 阴影投射
    /// </summary>
    public sealed class ProbeHallucinationDef : ProbeCardTemplate
    {
        public override CardConfig MakeConfig()
        {
            CardConfig config = GetCardDefaultConfig();

            config.Rarity = Rarity.Uncommon;
            config.Type = CardType.Skill;
            config.TargetType = TargetType.Nobody;

            config.Colors = new List<ManaColor>() { ManaColor.Blue };
            config.Cost = new ManaGroup() { Blue = 1 , Any = 1 };
            config.UpgradedCost = new ManaGroup() { Blue = 1 };


            config.Mana = ManaGroup.Empty;
            config.Value1 = 1;

            config.Index = CardIndexGenerator.GetUniqueIndex(config);
            return config;
        }
    }

    /// <summary>
    /// 幻象：
    /// 获取手牌一张攻击牌的复制，它伤害尽可能为0且暂塑为0，具有消耗、虚无
    /// </summary>
    [EntityLogic(typeof(ProbeHallucinationDef))]
    public sealed class ProbeHallucination : ProbeCard
    {
        /// <summary>
        /// 复制的卡牌数量
        /// </summary>
        public int CardCount
        {
            get => Value1;
        }

        public override Interaction Precondition()
        {
            List<Card> list = base.Battle.HandZone.Where((Card hand) => hand != this && hand.Config.Type == CardType.Attack).ToList<Card>();
            if (list.Count <= 0)
            {
                return null;
            }
            return new SelectHandInteraction(1, 1, list);
        }

        protected override IEnumerable<BattleAction> Actions(UnitSelector selector, ManaGroup consumingMana, Interaction precondition)
        {
            if (precondition != null)
            {
                Card origin = ((SelectHandInteraction)precondition).SelectedCards[0];
                List<Card> list = new List<Card>();
                for (int i = 0; i < CardCount; i++)
                {
                    Card card = origin.CloneBattleCard();
                    card.SetTurnCost(base.Mana);
                    card.IsEthereal = true;
                    card.IsExile = true;
                    card.IsCopy = true;
                    card.DeltaDamage = -card.RawDamage+1;
                    list.Add(card);
                }
                yield return new AddCardsToHandAction(list);
            }
        }
    }
}
